<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<style>
    #allinfo{left: 300px;position: absolute;top: 10px;}
    #allinfo span{margin-right: 10px;color: #999}
</style>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">年度</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="year" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_y">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">标书编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="bsnum" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" name="weier" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">归属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">招标代理公司</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhaounit" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">投标文件递交方式</label>
                        <div class="layui-input-block">
                            <div id="touditype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">开标时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="kaidt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">提成是否发放：</label>
                        <div class="layui-input-block">
                            <select id="ischeng" name="ischeng" lay-filter="ischeng">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
    <div id="allinfo"></div>
</script>
<script>




    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('代写业务统计');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_bian_lan_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);


                var allStr = '';
                allStr += '<span>全部应收款合计：'+parseFormatNum(res.data.all_biaofee)+'</span>';
                allStr += '<span>全部实收款合计：'+parseFormatNum(res.data.all_shishou)+'</span>';
                allStr += '<span>全部待收款合计：'+parseFormatNum(res.data.all_daishou)+'</span>';
                $("#allinfo").html(allStr);


                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(res.data.is_state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else {
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }

                }
                $("#state").html(state_str);

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                xmselect_dan('zhaotype', res.data.zhaotype, res.data.is_zhaotype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                xmselect_dan('touditype', res.data.touditype, res.data.is_touditype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })



                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", rowspan:2}
                ,{type:'numbers',title:'序号',totalRowText: '合计',rowspan:2}
                ,{field: 'bsnum', title: '标书编号',merge:['name'],rowspan:2}
                ,{field: 'number', title: '项目编号',merge:['name'],rowspan:2,hide:true}
                ,{field:'name',title:'项目名称',merge:true,rowspan:2,templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../bid/show.php?id='+d.id+'\')">'+d.name+'</span>';
                    }}
                ,{field: 'entype_name', title: '项目类别',merge:['name'],rowspan:2}
                ,{field: 'weier', title: '委托方',merge:['name'],rowspan:2}
                ,{field: 'zhaotype_name', title: '招标方式',merge:['name'],rowspan:2}
                ,{field: 'zhaounit', title: '招标代理公司',merge:['name'],rowspan:2}
                ,{field: 'kaidt', title: '开标时间',merge:['name'],rowspan:2}
                ,{field: 'touditype_name', title: '投标文件递交方式',merge:['name'],rowspan:2}
                ,{field: 'ischeng', title: '提成是否发放',merge:['name'],rowspan:2,templet: function(d){
                    return '<span class="ischeng">'+d.ischeng+'<span class="chengshuo layui-hide">'+d.chengshuo+'</span>'+'</span>';
                }}
                ,{field: '', title: '投标单位',colspan:2,align:'center'}
                ,{field: '', title: '收款情况',colspan:4,align:'center'}
                ,{field: '', title: '预算部',colspan:4,align:'center'}
                ,{field: '', title: '资料部',colspan:2,align:'center'}
                ,{field: '', title: '最终审核',colspan:2,align:'center'}
            ],
            [
                {field: 'touunit', title: '单位名称'}
                ,{field: 'touxing_name', title: '性质'}

                ,{field:'biaofee',title:'应收款(元)',totalRow: true,align:'right',templet: function(d){return parseFormatNum(d.biaofee);}}
                ,{field:'shishou',title:'实收款(元)',totalRow: true,align:'right',templet: function(d){return parseFormatNum(d.shishou);}}
                ,{field: 'shoudt', title: '收款日期'}
                ,{field:'daishou',title:'待收款(元)',totalRow: true,align:'right',templet: function(d){
                    if(d.daishou > 0){
                        return '<span class="colorhong">'+parseFormatNum(d.daishou)+'</span>';
                    }else{
                        return parseFormatNum(d.daishou);
                    }
                }}

                ,{field: 'suan_tu_name', title: '土建预算'}
                ,{field: 'bi_tu', title: '提成占比(%)'}
                ,{field: 'suan_an_name', title: '安装预算'}
                ,{field: 'bi_an', title: '提成占比(%)'}
                ,{field: 'zi_shen_name', title: '资审'}
                ,{field: 'bi_shen', title: '提成占比(%)'}
                ,{field: 'shen_suan_name', title: '预算审核'}
                ,{field: 'shen_zi_name', title: '资料审核'}
            ]
            ]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);


                $(".ischeng").hover(function(){
                    var mst = $(this).find('.chengshuo').text();
                    hhzhu_index = layer.tips(mst,this,{time:0});},function(){layer.close(hhzhu_index);
                });

            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_dai(buttitle){
        var idArr = get_table_check_touidarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        openPageEdit('dai.php?close=1&ids='+idArr.join(','));
    }

    function get_table_check_touidarr(datalist='datalist') {
        var checkStatus = layui.table.checkStatus(datalist).data;
        var ids = [];
        for(var i=0;i<checkStatus.length;i++){
            ids.push(checkStatus[i].touid)
        }
        return ids;
    }


    function auth_but_func_cheng(buttitle){
        var idArr = get_table_check_bididarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        openPageEdit('cheng.php?close=1&ids='+idArr.join(','), '770px', '490px');
    }

    function get_table_check_bididarr(datalist='datalist') {
        var checkStatus = layui.table.checkStatus(datalist).data;
        var ids = [];
        for(var i=0;i<checkStatus.length;i++){
            ids.push(checkStatus[i].id)
        }
        return ids;
    }

</script>
</body>
</html>
